﻿using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TunnelManager.Tools;

namespace TunnelManager.SearchAndReport.FCMS
{
    public partial class FCMS_Search : Form
    {
        public FCMS_Search()
        {
            InitializeComponent();
        }
 
        private void TranTheParam()
        {
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("startdate", dateTimePicker_start.Value.ToLongDateString()));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("starttime", dateTimePicker_start.Value.ToLongTimeString()));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("enddate", dateTimePicker_end.Value.ToLongDateString()));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("endtime", dateTimePicker_end.Value.ToLongTimeString()));
            this.reportViewer1.LocalReport.SetParameters(new ReportParameter("user", User.Username));
        }

        private void Command_Search_Resize(object sender, EventArgs e)
        {
            LocationPut();
        }
        private void LocationPut()
        {
            reportViewer1.Size = new Size(this.ClientSize.Width, this.ClientSize.Height - 93);
            panel1.Location = new Point(0, this.ClientSize.Height - 70);
        }

        private void button_watch_Click(object sender, EventArgs e)
        {
            TranTheParam();
            fCMSReportTableAdapter.Fill(tunnelXAT1DataSet.FCMSReport,  devicechose.SelectedValue.ToString(),Convert.ToDateTime(dateTimePicker_start.Text.Trim()), Convert.ToDateTime(dateTimePicker_end.Text.Trim()));
            this.reportViewer1.RefreshReport();
        }

        private void button_watch_MouseEnter(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Hand;
        }

        private void button_watch_MouseLeave(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Arrow;
        }

        

        private void devicechose_SelectedIndexChanged_1(object sender, EventArgs e)
        {

        }

        private void FCMS_Search_Load(object sender, EventArgs e)
        {
            //定义选择设备下拉框内容//
            string sql = "select DeviceID,Name from V_DeviceTable where DeviceID ='FCMS1' OR DeviceID ='FCMS2'";
            SqlDBHelper sdh = new SqlDBHelper();
            DataTable dt = sdh.GetTable(sql);
            devicechose.DataSource = dt;

            LocationPut();

            TranTheParam();
            fCMSReportTableAdapter.Fill(tunnelXAT1DataSet.FCMSReport, devicechose.SelectedValue.ToString(), Convert.ToDateTime(dateTimePicker_start.Text.Trim()), Convert.ToDateTime(dateTimePicker_end.Text.Trim()));
            this.reportViewer1.RefreshReport();
        }

        private void FCMS_Search_Resize(object sender, EventArgs e)
        {
            LocationPut();
        }
    }
}
